//------------------------------------------------------------------------------
// <copyright file="EFOracleProviderFactory.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace EFOracleOdpProvider
{
    using System;
    using System.Data;
    using System.Data.Common;
    using System.Diagnostics.CodeAnalysis;
    using Oracle.DataAccess;
    using Oracle.DataAccess.Client;

    /// <summary>
    /// Class representing a provider factory for the EFOracleOdpProvider provider.
    /// </summary>
    public partial class EFOracleOdpProviderFactory : DbProviderFactory, IServiceProvider
    {
        /// <summary>
        /// A singleton object for the entity client provider factory object
        /// </summary>
        [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "EFOracleOdpProviderFactory implements the singleton pattern and it's stateless. This is needed in order to work with DbProviderFactories.")]
        public static readonly EFOracleOdpProviderFactory Instance = new EFOracleOdpProviderFactory();

        /// <summary>
        /// Constructs the EFOracleOdpProviderFactory object, this is private as users shouldn't create it directly
        /// </summary>
        public EFOracleOdpProviderFactory()
        {
        }

        /// <summary>
        /// Creates a EFOracleCommand object and returns it
        /// </summary>
        /// <returns>A EFOracleCommand object</returns>
        public override DbCommand CreateCommand()
        {
            return new EFOracleOdpCommand();
        }

        /// <summary>
        /// Creates a EFOracleCommandBuilder object and returns it
        /// </summary>
        /// <returns>A EFOracleCommandBuilder object</returns>
        public override DbCommandBuilder CreateCommandBuilder()
        {
            return new OracleCommandBuilder();
        }

        /// <summary>
        /// Creates a EFOracleConnection object and returns it
        /// </summary>
        /// <returns>A EFOracleConnection object</returns>
        public override DbConnection CreateConnection()
        {
            return new EFOracleOdpConnection();
        }

        /// <summary>
        /// Creates a EFOracleConnectionStringBuilder object and returns it
        /// </summary>
        /// <returns>A EFOracleConnectionStringBuilder object</returns>
        public override DbConnectionStringBuilder CreateConnectionStringBuilder()
        {
            return new OracleConnectionStringBuilder();
        }

        /// <summary>
        /// Creates a DbDataAdapter object and returns it, this method is currently not supported
        /// </summary>
        /// <returns>A DbDataAdapter object</returns>
        public override DbDataAdapter CreateDataAdapter()
        {
            return new OracleDataAdapter();
        }

        /// <summary>
        /// Creates a EFOracleParameter object and returns it
        /// </summary>
        /// <returns>A EFOracleParameter object</returns>
        public override DbParameter CreateParameter()
        {
            return new OracleParameter();
        }

        /// <summary>
        /// Extension mechanism for additional services;  
        /// </summary>
        /// <returns>requested service provider or null.</returns>
        object IServiceProvider.GetService(Type serviceType)
        {
            if (serviceType == typeof(DbProviderServices))
                return EFOracleOdpProviderServices.Instance;
            else
                return null;
        }
    }
}
